package com.neuedu.common.file.repository;

import com.neuedu.common.file.domain.model.FileRequest;
import com.neuedu.common.file.domain.model.FileResponse;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import java.io.InputStream;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;

public interface FileRepository {

    /**
     * 存储
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "file", value = "文件", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse save(MultipartFile file, FileRequest request) throws Exception;

    /**
     * 存储
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "bytes", value = "文件字节数组", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse save(byte[] bytes, FileRequest request) throws Exception;

    /**
     * 存储
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "inputStream", value = "输入流", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse save(InputStream inputStream, FileRequest request) throws Exception;

    /**
     * 存储M3U8视频文件
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "inputStream", value = "输入流", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
        @ApiImplicitParam(name = "partition", value = "分区", required = true),
    })
    FileResponse saveM3U8(InputStream inputStream, FileRequest request, String partition) throws Exception;


    /**
     * 删除原文件并存储新文件
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "file", value = "文件", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "新文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "新文件名", required = true),
        @ApiImplicitParam(name = "request.rawFilePath", value = "旧文件路径", required = true),
        @ApiImplicitParam(name = "request.rawFileName", value = "旧文件名", required = true),
    })
    FileResponse update(MultipartFile file, FileRequest request) throws Exception;

    /**
     * 删除原文件并存储新文件
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "bytes", value = "文件字节数组", required = true),
        @ApiImplicitParam(name = "request.filePath", value = "新文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "新文件名", required = true),
        @ApiImplicitParam(name = "request.rawFilePath", value = "旧文件路径", required = true),
        @ApiImplicitParam(name = "request.rawFileName", value = "旧文件名", required = true),
    })
    FileResponse update(byte[] bytes, FileRequest request) throws Exception;

    /**
     * 拷贝
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "新文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "新文件名", required = true),
        @ApiImplicitParam(name = "request.rawFilePath", value = "旧文件路径", required = true),
        @ApiImplicitParam(name = "request.rawFileName", value = "旧文件名", required = true),
    })
    FileResponse copy(FileRequest request) throws Exception;

    /**
     * 删除
     * 谨慎使用
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名，非必传，如果不传直接把路径的文件夹删了", required = false),
    })
    FileResponse delete(FileRequest request) throws Exception;

    /**
     * 删除
     * 谨慎使用
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名，非必传，如果不传直接把路径的文件夹删了", required = false),
    })
    FileResponse remove(FileRequest request) throws Exception;

    /**
     * 单个获取
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse getBytes(FileRequest request) throws Exception;

    /**
     * 获取文件URL
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse getUrl(FileRequest request) throws Exception;

    /**
     * 单个获取
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    FileResponse getInputStream(FileRequest request) throws Exception;

    /**
     * 批量获取
     */
    @ApiImplicitParams({
        @ApiImplicitParam(name = "request.filePath", value = "文件路径", required = true),
        @ApiImplicitParam(name = "request.fileName", value = "文件名", required = true),
    })
    List<FileResponse> query(List<FileRequest> requestList) throws Exception;

}
